import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [	
	// 一级布局
	{
		path:'/',
		component:()=>import('@/views/Layout'),
		children:[
			{
				path:'/',
				component:()=>import('@/views/home')
			},
			{
				path:'/category/:id',
				component:()=>import('@/views/category/index')
			},
			{ 
				path: '/category/sub/:id',
				component:()=>import('@/views/category/sub')
			},
			{ 
				path: '/product/:id',
				component:()=>import('@/views/goods/index')
			},
			{ 
				path: '/cart',
				component:()=>import('@/views/cart/index')
			}
		]
	},
	{
		path:'/login',
		component:()=>import('@/views/login/index')
	},
	{ 
		path: '/login/callback',
	 	component: import('@/views/login/callback') 
	}
]

const router = createRouter({
	history: createWebHashHistory(),
	routes,
	// 每次切换路由 页面滚动到顶部
	scrollBehavior () {
		// vue2.0 通过 x y 控制
		// vue3.0 通过left top 控制	
		return { left: 0, top: 0 }
	}
})

export default router
